package com.nan.common;

import com.jfinal.config.Constants;
import com.jfinal.config.Handlers;
import com.jfinal.config.Interceptors;
import com.jfinal.config.JFinalConfig;
import com.jfinal.config.Plugins;
import com.jfinal.config.Routes;
import com.jfinal.core.JFinal;
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
import com.jfinal.plugin.c3p0.C3p0Plugin;
import com.jfinal.render.ViewType;
import com.nan.controller.IndexController;
import com.nan.controller.ManageController;
import com.nan.controller.ResTypeController;
import com.nan.controller.ResourceController;
import com.nan.controller.UserController;
import com.nan.model._MappingKit;

public class Config extends JFinalConfig {

	@Override
	public void configConstant(Constants me) {
		me.setDevMode(true);
		me.setViewType(ViewType.JSP);
		me.setBaseDownloadPath("files");
		me.setBaseUploadPath("files");
	}

	@Override
	public void configRoute(Routes me) {
		me.add("/", IndexController.class);
		me.add("/index", IndexController.class);
		me.add("/user", UserController.class);
		me.add("/manage", ManageController.class);
		me.add("/resource", ResourceController.class);
		me.add("/restype", ResTypeController.class);
	}

	@Override
	public void configPlugin(Plugins me) {
		loadPropertyFile("dbconfig.properties");
		C3p0Plugin c3p0Plugin = new C3p0Plugin(getProperty("jdbcUrl"), getProperty("username"), getProperty("password"));
		me.add(c3p0Plugin);
		ActiveRecordPlugin arp = new ActiveRecordPlugin(c3p0Plugin);
		me.add(arp);
		_MappingKit.mapping(arp);
	}

	@Override
	public void configInterceptor(Interceptors me) {

	}

	@Override
	public void configHandler(Handlers me) {

	}

	public static void main(String[] args) {
		JFinal.start("WebRoot", 8080, "/", 5);
	}

}
